<template>
  <Modal v-model="show" width="1190" title="池内采用网站列表" class="ivu-modal--custom">
    <div class="list-table-box">
      <CommonTablePage
        class="ivu-table--no-border"
        :columns="columns"
        :tableData="tableData"
        :total="pagination.total"
        @on-change="handlePageChange"
        @on-page-size-change="handlePageSizeChange"
      ></CommonTablePage>
    </div>
    <template #footer>
      <!-- <div class="text-center">
          <Button class="ivu-btn--round" @click="cancel">取消</Button>
          <Button class="ml14 ivu-btn--round" type="primary" @click="handleFormSubmit">上传</Button>
        </div> -->
    </template>
  </Modal>
</template>

<script>
import CommonTablePage from '@/components/common/CommonTablePage/CommonTablePage'
// util
import { createCommonPagination } from '@/utils/service.js'
import { createForm, createColumns } from './service'
// request
import { getEntryAdoptListById } from '@/api/provideEnd/entryManyscript'
export default {
  name: 'ModalAdoptList',

  components: { CommonTablePage },

  props: {
    visible: { type: Boolean },

    id: { type: [String, Number] },
  },

  data() {
    return {
      formData: createForm(),

      columns: createColumns(this),
      tableData: [],

      pagination: createCommonPagination(),
    }
  },

  computed: {
    show: {
      get() {
        return this.visible
      },

      set(v) {
        this.$emit('update:visible', v)
      },
    },
  },

  watch: {
    id(v) {
      if (!v) return
      this.getEntryAdoptListById(this.id, this.formData)
    },

    visible(v) {
      /* 关闭时清空数据 */
      if (!v) {
        this.resetData()
      }
    },
  },

  methods: {
    resetData() {
      this.formData = createForm()
      this.tableData = []
      this.pagination.total = 0
    },

    async getEntryAdoptListById(id, params) {
      /* {
      "id": 1,
      "title": "关于印发《关于加快农业保险高质量发展的指导意见》的通知",
      "siteName": "青龙网",
      "adoptedTime": "2024-08-12 14:16:00"
      } */
      const res = await getEntryAdoptListById(id, params)
      const data = res.data.data || {}
      this.tableData = Object.freeze(data.data || [])
      this.pagination.total = data.count || 0
    },

    handlePageChange(page) {
      this.formData.pageNo = page
      this.getEntryAdoptListById(this.id, this.formData)
    },
    handlePageSizeChange(pageSize) {
      this.formData.pageSize = pageSize
      this.getEntryAdoptListById(this.id, this.formData)
    },
  },
}
</script>

<style lang="less" scoped>
.ivu-modal--custom {
  /deep/ .ivu-modal-body {
    padding-bottom: 0;
  }
  /deep/ .ivu-modal-footer {
    display: none;
  }
}
</style>
